package org.xiangfei.demo.netty;

import java.util.logging.Level;
import java.util.logging.Logger;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.xiangfei.demo.netty.codec.Auth;

public class AuthClientHandler extends ChannelInboundHandlerAdapter{
    private Logger logger=Logger.getLogger(AuthClientHandler.class.getName());

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        logger.log(Level.INFO, "AuthClientInitHandler exceptionCaught");
        Auth.AuthRequest request=Auth.AuthRequest.newBuilder()
                             .setUserId("010203")
                             .setPassword("abcde")
                             .build();
        ctx.writeAndFlush(request);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg)
            throws Exception {
        logger.log(Level.INFO, "AuthClientInitHandler channelRead");
        Auth.AuthResponse response=(Auth.AuthResponse)msg;
        System.out.println("response: code="+response.getResultCode()+", message="+response.getResultMessage());
        //ctx.close();
    }
}